//
// Created by vcq on 21/4/2.
//
#include "model/profession.hpp"

static void GetProfession(request &req, response &res) {
    if (!check_login(req, res)) {
        return;
    }
    basic_string_view<char> id = req.get_query_value("id");
    basic_string_view<char> _school_id = req.get_query_value("_school_id");
    json item = mgetProfession(id, _school_id);
    res.set_status_and_content(status_type::ok, item.dump(), req_content_type::json);
}

static void SaveProfession(request &req, response &res) {
    if (!check_login(req, res)) {
        return;
    }
    struct profession profession1{};
    profession1.id = atoi(req.get_query_value("id").data());
    profession1.name = req.get_query_value("name");
    profession1._school_id = atoi(req.get_query_value("_school_id").data());
    profession1.note = req.get_query_value("note");
    MAddProfession(profession1);
    res.set_status_and_content(status_type::ok);
}

static void DeleteProfession(request &req, response &res) {
    if (!check_login(req, res)) {
        return;
    }
    MDeleteProfession(req.get_query_value("id"));
    res.set_status_and_content(status_type::ok);
}